package com.darkteam.jhades.cs.message;

import java.util.ArrayList;
import java.util.List;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;

import com.darkteam.jhades.common.message.JHadesSerializable;

public class ServerListMessage implements JHadesSerializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5633105633239885729L;

	private List<ServerNode> serverNodes = new ArrayList<ServerNode>();

	public boolean add(ServerNode e) {
		return serverNodes.add(e);
	}

	public void clear() {
		serverNodes.clear();
	}

	public ServerNode get(int index) {
		return serverNodes.get(index);
	}

	public boolean isEmpty() {
		return serverNodes.isEmpty();
	}

	public ServerNode remove(int index) {
		return serverNodes.remove(index);
	}

	public int size() {
		return serverNodes.size();
	}

	@Override
	public ChannelBuffer toChannelBuffer() {
		ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
		buffer.writeShort((short) serverNodes.size());
		for (ServerNode serverNode : serverNodes) {			
			buffer.writeBytes(serverNode.toChannelBuffer());			
		}
		
		return buffer;
	}

}
